<template>
  <div class="main">
    <el-row>
      <el-form :inline="true" label-width="80px" labelPosition="left" :model="searchForm">
        <el-col :span="18">
          <el-form-item label="关键字">
            <el-input v-model="searchForm.keyword" placeholder="请输入" style="width:300px"></el-input>
          </el-form-item>
          <el-button type="primary" icon="el-icon-search" @click.native="searchSales">搜索</el-button>
        </el-col>
        
      </el-form>
    </el-row>
    <el-row>
      <el-table
        :data="salesList"
        :cell-style="$rowstyle"
        :header-cell-style="$headerstyle"
        style="width: 100%"
        max-height="250"
      >
        <el-table-column prop="get_admin_info.name" label="姓名" align="center"></el-table-column>
        <el-table-column prop="get_admin_info.mobile" label="电话" align="center"></el-table-column>
        <el-table-column prop="get_admin_info.email" align="center" label="邮箱"></el-table-column>
        <el-table-column prop="get_admin_info.door_name" align="center" label="部门"></el-table-column>

        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="saleChoose(scope.row)"
              type="text"
              size="small"
              v-if="sales.id != scope.row.id"
            >选择</el-button>
            <el-button
              @click.native.prevent="saleCancelChoose(scope.row)"
              type="text"
              size="small"
              v-else
            >取消选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @current-change="handlePageChange"
        :current-page.sync="currentPage"
        :page-size="4"
        layout="prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-row>
  </div>
</template>

<script>
import {
  Choice_Salesman
} from "../../../api/Salesman.js";
import { SETDATE } from "../../../api/System.js";
export default {
    props:['sales'],
  data() {
    return {
      searchForm: {
        keyword: ""
      },
      total: 0,
      currentPage: 1,
      salesList: []
    };
  },
  methods: {
    getChoice_Salesman(data) {
      let params = data ? data : {
            name: this.searchForm.keyword,
            page: this.currentPage,
            per: 4
          };

      Choice_Salesman(params).then(res => {
        if (res.code == 200) {
          this.salesList = res.data.data;
          this.currentPage = res.data.current_page;
          this.total = res.data.total;
        } else {
          this.$message.error("获取销售人员错误,请重试");
        }
      });
    },
    searchSales(){
        this.getChoice_Salesman()
    },
    handlePageChange() {
        this.getChoice_Salesman()
    },
    saleChoose(data){
        this.$emit('saleChoose',data)
    },
    saleCancelChoose(){
        this.$emit('saleCancelChoose')
    }
  },
  mounted(){
      this.getChoice_Salesman()
  }
};
</script>

<style scoped>
.main {
  width: 100%;
  height: 100%;
}
</style>